﻿using Edu.Localization.Edu;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Localization;
using System.Threading.Tasks;
using Volo.Abp.AspNetCore.Mvc.UI.Theme.SB;
using Volo.Abp.TenantManagement.Web.Navigation;
using Volo.Abp.UI.Navigation;

namespace Edu.Menus
{
    public class EduMenuContributor : IMenuContributor
    {
        public async Task ConfigureMenuAsync(MenuConfigurationContext context)
        {
            if (context.Menu.Name == StandardMenus.Main)
            {
                await ConfigureMainMenuAsync(context);
            }
        }

        private Task ConfigureMainMenuAsync(MenuConfigurationContext context)
        {
            if (!EduConsts.IsMultiTenancyEnabled)
            {
                ApplicationMenuItem administration = context.Menu.GetAdministration();
                administration.TryRemoveMenuItem(TenantManagementMenuNames.GroupName);
            }

            var l = context.ServiceProvider.GetRequiredService<IStringLocalizer<EduResource>>();

            context.Menu.Items.Insert(0, new ApplicationMenuItem("Edu.Home", l["Menu:Home"], "/"));


            var appGroup = new ApplicationMenuItem("applicaiton", "APPLICATION", customData: SBThemeConstant.MENU_GROUP_NAME);

            var achievement = new ApplicationMenuItem("Achievement", "成就", icon: "fas fa-lemon");
            achievement.AddItem(new ApplicationMenuItem("AchievementConfig", "成就配置", url: "/Achievement"));
            achievement.AddItem(new ApplicationMenuItem("UserAchievement", "用户成就", url: "/UserAchievement"));

            appGroup.AddItem(achievement);
            var task = new ApplicationMenuItem("studyTask", "任务", url: "/StudyTask", icon: "fas fa-file-invoice");
            appGroup.AddItem(task);


            var import = new ApplicationMenuItem("ImportData", "导入数据", url: "/ImportData", icon: "fas fa-file-invoice");
            appGroup.AddItem(import);

            context.Menu.AddItem(appGroup);
            return Task.CompletedTask;
        }
    }
}
